import http from "@/axios";
import type {BaseResponse, PageBaseResponse} from "@/api/baseResponse";
import type {PageBaseRequest} from "@/api/baseRequest";

enum ApiUrl {
    pageAclUrl = "/mqtt/acl/page",
    createAclUrl = "/mqtt/acl/create",
    updateAclUrl = "/mqtt/acl/update",
    deleteAclUrl = "/mqtt/acl/delete"
}

export interface AclResponse {
    id: number;
    permission: number;
    username: string;
    action: number;
    topic: string;
    createDatetime: string;
}

export interface PageAclRequest extends PageBaseRequest {
    permission?: number;
    username?: string;
    action?: number;
    topic?: string;
}

export interface CreateAclRequest {
    permission?: number;
    username?: string;
    action?: number;
    topic?: string;
}

export interface UpdateAclRequest extends CreateAclRequest {
    id?: number;
}

export function createAcl(data: CreateAclRequest) {
    return http.post<BaseResponse<boolean>>(ApiUrl.createAclUrl, data);
}

export function updateAcl(data: UpdateAclRequest) {
    return http.put<BaseResponse<boolean>>(ApiUrl.updateAclUrl, data);
}

export function deleteAcl(id: number) {
    return http.delete<BaseResponse<boolean>>(ApiUrl.deleteAclUrl, {
        params: {
            id: id
        }
    })
}

export function pageAcl(data: PageAclRequest) {
    return http.post<PageBaseResponse<AclResponse[]>>(ApiUrl.pageAclUrl, data)
}